import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/29 14:54
 * @description 思路，将数对排序，a[0]相同时，按a[1]升序；不同时，按a[0]升序，然后统计个数
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] pairs = {{-6,9},{1,6},{8,10},{-1,4},{-6,-2},{-9,8},{-5,3},{0,3}};
        solution.findLongestChain(pairs);
    }
    public int findLongestChain(int[][] pairs) {
        Arrays.sort(pairs, (a, b) -> {
            return a[1] - b[1];
        });
        int ans = 1, minN = pairs[0][1];
        for (int i = 1; i < pairs.length; i++) {
            if (pairs[i][0] > minN) {
                ans++;
                minN = pairs[i][1];
            }
        }
        return ans;
    }
}
